package horncomb.bpm.process;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import horncomb.bpm.process.core.ProcessDefinition;
import horncomb.bpm.process.core.ProcessInstance;
import horncomb.bpm.process.core.ProcessInstanceCreator;
import horncomb.bpm.process.core.Token;
import horncomb.bpm.process.instance.TokenCreator;

/**
 * @author Daniel
 */
public interface ProcessManager {

	public Token findTokenByBizEntityId(String bizEntityId);

	public Map<String, ? extends Token> findTokenByBizEntityIds(
			Collection<String> bizEntityIds);

	public ProcessInstance start(String id, Object contextModel);

	public ProcessInstance start(Token parentToken, String id,
			Object contextModel);

	public Token findToken(String id);

	/**
	 * @param parentId
	 * @return
	 */
	public ProcessInstance findProcessInstance(String id);

	/**
	 * @param id
	 */
	public List<? extends ProcessInstance> findNestedProcessInstance(
			String procInstId);

	/**
	 * 根据流程id删除流程下所有内容，包括子流程、子token、办理意见等
	 * @param processInstanceId
	 */
	public void deleteProcessInstance(String processInstanceId);

	public void performProcessTransition(String processInstanceId,
			String transitionId, Object args);

	public void performTransition(String tokenId, String transitionId,
			Object args);

	/**
	 * @param processDefinition
	 */
	public void deploy(ProcessDefinition processDefinition);

	public ProcessDefinition findProcessDefinition(String id);

	/**
	 * @param id
	 * @return
	 */
	public boolean hasNestedProcessInstance(String parentStateDescId);

	/**
	 * @param processInstanceId
	 * @param parent
	 * @param contextModel
	 * @param creator
	 * @return
	 */
	public Token invokeCreateToken(String processInstanceId, Token parent,
			Object contextModel, TokenCreator creator);

	public ProcessInstance invokeCreateProcessInstance(Token parentToken,
			ProcessDefinition processDefinition, Object contextModel,
			ProcessInstanceCreator creator);

	public List<? extends Token> findSubTokens(String parentId);

	/**
	 * 统计在某状态的子token个数
	 * @param id
	 */
	public int countSubTokenInState(String parentTokenId, String[] stateIds);

	/**
	 * @param id
	 * @return
	 */
	public int countSubTokens(String parentId);

	public void update(ProcessInstance processInstance);

	public void update(Token token);

	/**
	 * 删除token，包括其下的子token
	 * @param tokenId
	 */
	public void deleteToken(String tokenId);

}